package DAO;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONObject;

import android.R.integer;
import anroid.vstore.provider.Helper;
import DTO.VideoDTO;

public class VideoDAO {
	public static ArrayList<VideoDTO> GetVideos(Integer isHot,Integer isViews,Integer isNew,Integer limit)
	{
		ArrayList<VideoDTO> list = new ArrayList<VideoDTO>();
		String url = Helper.SERVICE_URL + "api/listvideo.php?";
		url+= "isHot="+ isHot.toString();
		url+= "&isViews="+ isViews.toString();
		url+= "&isNews="+isNew.toString();
		url+= "&limit="+ limit.toString(); 
		
		String jsonStr = ServiceHandler.makeServiceCall(url, ServiceHandler.GET);
		if (jsonStr != null) {
			try {
				JSONArray jsonArr = new JSONArray(jsonStr);
				for(int i =0 ; i < jsonArr.length();i++)
				{
					JSONObject c = jsonArr.getJSONObject(i);
					VideoDTO video = new VideoDTO();
					video.Id = c.getInt("Id");
					video.caption = c.getString("name");
					video.imgURL = c.getString("thumb");
					video.link = c.getString("link");
					list.add(video);
				}
				
			}catch(Exception e){
				}
			}
		return list;
	}
}
